﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using IBatisNet.DataAccess;
using IBatisNet.Common.Pagination;
using IBatisNet.DataAccess.Interfaces;

using MW.Domain.DC;
using MW.Service;
using MW.Persistence.Interface;
using MW.Persistence.Interface.DC;


namespace MW.Service
{
    public class MetaService
    {
        private static MetaService _instance = new MetaService();
        private IDaoManager _daoManager = null;
        private IMetaDao _Meta = null;

        private MetaService() 
		{
			_daoManager = ServiceConfig.GetInstance().DaoManager;
            _Meta = (IMetaDao)_daoManager.GetDao(typeof(IMetaDao));
		}

        public static MetaService GetInstance()
        {
            return _instance;
        }

        public Meta GetMeta(string metaID)
        {
            Meta mReturn = null;
            _daoManager.OpenConnection();
            mReturn = _Meta.GetMeta(metaID);
            _daoManager.CloseConnection();
            return mReturn;
        }

        public void InsertMeta(Meta meta)
        {
            try
            {
                _daoManager.BeginTransaction();
                _Meta.InsertMeta(meta);
                _daoManager.CommitTransaction();
            }
            catch
            {
                _daoManager.RollBackTransaction();
                throw;
            }
        }

        public IPaginatedList SearchMetaList(string keywords)
        {
            IPaginatedList iplReturn = null;
            _daoManager.OpenConnection();
            iplReturn = _Meta.SearchMetaList(keywords);
            _daoManager.CloseConnection();
            return iplReturn;
        }

        public IPaginatedList SearchMetaDCList(string keywords)
        {
            IPaginatedList iplReturn = null;
            _daoManager.OpenConnection();
            iplReturn = _Meta.SearchMetaDCList(keywords);
            _daoManager.CloseConnection();
            return iplReturn;
        }

        public IPaginatedList SearchMetaDCListColumn(string column, string keywords)
        {
            IPaginatedList iplReturn = null;
            _daoManager.OpenConnection();
            iplReturn = _Meta.SearchMetaDCListColumn(column, keywords);
            _daoManager.CloseConnection();
            return iplReturn;
        }

        public MetaDC GetMetaDCByUniqueID(string uniqueID)
        {
            MetaDC mdcReturn = null;
            _daoManager.OpenConnection();
            mdcReturn = _Meta.GetMetaDCByUniqueID(uniqueID);
            _daoManager.CloseConnection();
            return mdcReturn;
        }

        public IPaginatedList GetRelatedMeta(MetaDC metaDC)
        {
            IPaginatedList iplReturn = null;
            _daoManager.OpenConnection();
            iplReturn = _Meta.GetRelatedMeta(metaDC);
            _daoManager.CloseConnection();
            return iplReturn;
        }
    }
}
